<template>
    <div>
        <!--<span style="margin: 5px 0 5px 5px;font-size: 14px;">{{block.name}}</span>-->
        <div class="block-column" style="height: 44vw;">
            <div class="entry-container" style="height: 24vw;">
                <div v-if="block.blockEntry[0]" class="entry" @tap="handleEntryClick(0)">
                    <img :src="getImagePath(0)" style="position:absolute;width:100%;height:100%" />
                </div>
            </div>
            <div class="flex-row" style="height: 20vw;">
                <div class="entry-container" style="flex:1">
                    <div v-if="block.blockEntry[1]" class="entry" @tap="handleEntryClick(1)">
                        <img :src="getImagePath(1)" style="position:absolute;width:100%;height:100%" />
                    </div>
                </div>
                <div class="entry-container" style="flex:1">
                    <div v-if="block.blockEntry[2]" class="entry" @tap="handleEntryClick(2)">
                        <img :src="getImagePath(2)" style="position:absolute;width:100%;height:100%" />
                    </div>
                </div>
                <div class="entry-container" style="flex:1">
                    <div v-if="block.blockEntry[3]" class="entry" @tap="handleEntryClick(3)">
                        <img :src="getImagePath(3)" style="position:absolute;width:100%;height:100%" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

import { apiDomain, fetchDomain } from 'assets/js/Lib'

export default {
    data() {
        return {
            
        }
    },
    computed: {
        webApiDomain: function () {
            return apiDomain;
        }
    },
    components: {

    },
    props: {
        block: {
            type: Object,
            default: {}
        },
    },
    watch: {
    },
    //实例初始化最之前，无法获取到data里的数据
    beforeCreate() {
    },
    //在挂载开始之前被调用
    beforeMount() {
    },
    //已成功挂载，相当ready()
    mounted() {
        console.log('this.block', this.block);
    },
    //相关操作事件
    methods: {
      openPage: function (url) {
        if (!url) {
          return;
        }
        let pageConfig = {
          "id": url,
          "url": url,
          show: {
            autoShow: true
          },
          waiting: {
            title: '加载中...'
          }
        }

        mui.openWindow(pageConfig)
      },
        handleEntryClick(i) {
            console.log('handleEntryClick', i);
            if (!this.block.blockEntry[i]) {
                return;
            }
            let type = this.block.blockEntry[i].type;
            if (type == 1) {
                this.openPage(`${fetchDomain}/views/product.html?isBiYao=false&id=${this.block.blockEntry[i].product_id}`);
            } else if (type == 2) {
                this.openPage(this.block.blockEntry[i].url);
            }
        },
        getImagePath(i) {
            let type = this.block.blockEntry[i].type;
            if (type == 1) {
                let file = this.block.blockEntry[i].product.file;
                return `${apiDomain}/public/uploads/${file.savepath}${file.savename}`;
            } else if (type == 2) {
                let file = this.block.blockEntry[i].file;
                return `${apiDomain}/public/uploads/${file.savepath}${file.savename}`;
            }
        }
    }
}
</script>

<style scoped lang="less">
    .block-column {
        display: flex;
        flex-direction: column;
        height: 6rem;

        .flex-column {
            display: flex;
            flex-direction: column;
        }

        .flex-row {
            display: flex;
            flex-direction: row;
        }

        .entry {
            position: relative;
            overflow: hidden;
            width: 100%;
            height: 100%;
        }

        .entry-container {
            position: relative;
            border: 0.5px solid #eeeeee;
        }
    }
</style>
